﻿package com.sonishpere 
{
	import com.sonishpere.data.Countrys;
	import com.sonishpere.events.BlackHoleEvent;
	import com.saint.utils.Logger;
	import com.sonishpere.events.CountryButtonClickEvent;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author kembera
	 */
	public class Content extends Sprite
	{
		
		private var globe:MovieClip;
		private var sonisphereTitle:MovieClip;
		private var coming_soon:MovieClip;
		private var info_uk:InfoButton;
		private var info_pol:InfoButton;
		private var info_czec:InfoButton;
		private var info_swz:InfoButton;
		private var info_bul:InfoButton;
		private var info_gre:InfoButton;
		private var info_rom:InfoButton;
		private var info_tur:InfoButton;
		private var info_sp:InfoButton;
		private var info_fin:InfoButton;
		private var info_swe:InfoButton;
		
		private var infoX:Number = 6.5;
		
		private var infoButtonsStartY:Number = 100;
		private var YSpacer:Number = 4;
		private var infoButtonsCurrentY:Number;
		
		private var buttons:Array = new Array();
		
		public function Content() 
		{
			Logger.info("Content.Content");
			
			/* layour the elements */  
			
			Logger.debug("Content.Content: " + FlashVarsHolder.getInstance().SWZ_LIVE);
			
			globe = new Globe();
			globe.x = 450;
			globe.y = -10;
			
			sonisphereTitle = new Title_Sonisphere();
			sonisphereTitle.x = 0;
			sonisphereTitle.y = 0;
			
			coming_soon = new Coming_soon();
			coming_soon.x = infoX;
			coming_soon.y = 122;
			
			info_uk = new Info_uk();
			info_uk.init(FlashVarsHolder.getInstance().UK_LIVE);
			info_uk.addEventListener(CountryButtonClickEvent.CLICK, onUKClick);
			buttons.push(info_uk);
			
			info_pol = new Info_pol();
			info_pol.init(FlashVarsHolder.getInstance().POL_LIVE);
			info_pol.addEventListener(CountryButtonClickEvent.CLICK, onPOLClick);
			buttons.push(info_pol);		
			
			info_swz = new Info_swz();
			info_swz.addEventListener(CountryButtonClickEvent.CLICK, onSWZClick);
			info_swz.init(Boolean(FlashVarsHolder.getInstance().SWZ_LIVE));
			buttons.push(info_swz);		
			
			info_czec = new Info_czec();
			info_czec.addEventListener(CountryButtonClickEvent.CLICK, onCZECClick);
			info_czec.init(FlashVarsHolder.getInstance().CZEC_LIVE);
			buttons.push(info_czec);		
			
			info_bul = new Info_bul();
			info_bul.addEventListener(CountryButtonClickEvent.CLICK, onBULClick);
			info_bul.init(FlashVarsHolder.getInstance().BUL_LIVE );
			buttons.push(info_bul);			
			
			info_gre = new Info_gre();
			info_gre.addEventListener(CountryButtonClickEvent.CLICK, onGREClick);
			info_gre.init(FlashVarsHolder.getInstance().GRE_LIVE );
			buttons.push(info_gre);			
			
			info_rom = new Info_rom();
			info_rom.addEventListener(CountryButtonClickEvent.CLICK, onROMClick);
			info_rom.init(FlashVarsHolder.getInstance().ROM_LIVE);
			buttons.push(info_rom);			
			
			info_tur = new Info_tur();
			info_tur.addEventListener(CountryButtonClickEvent.CLICK, onTURClick);
			info_tur.init(FlashVarsHolder.getInstance().TRK_LIVE);
			buttons.push(info_tur);			
			
			info_sp = new Info_sp();
			info_sp.addEventListener(CountryButtonClickEvent.CLICK, onSPClick);
			info_sp.init(FlashVarsHolder.getInstance().ESP_LIVE);
			buttons.push(info_sp);			
			
			info_swe = new Info_swe();
			info_swe.init(FlashVarsHolder.getInstance().SWE_LIVE);
			info_swe.addEventListener(CountryButtonClickEvent.CLICK, onSWEClick);
			buttons.push(info_swe);			
			
			info_fin = new Info_fin();
			info_fin.addEventListener(CountryButtonClickEvent.CLICK, onFINClick);
			info_fin.init(FlashVarsHolder.getInstance().FIN_LIVE);
			buttons.push(info_fin);			
			
			
		}
				
		
		private function onTURClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.TURKEY));	
		}
		
		private function onSPClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.SPAIN));
		}
		
		private function onROMClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.ROMANIA));
		}
		
		private function onGREClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.GREECE));
		}
		
		private function onBULClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.BULGARIA));
		}
		
		private function onSWZClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.SWITZERLAND));
		}
		
		private function onCZECClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.CZECH_REPUBLIC));			
		}
		
		private function onUKClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.UNITED_KINGDOM));
		}
		private function onPOLClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.POLAND));
		}
		private function onFINClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.FINLAND));
		}
		private function onSWEClick(e:CountryButtonClickEvent):void 
		{
			dispatchEvent(new CountryButtonClickEvent(CountryButtonClickEvent.CLICK, Countrys.SWEDEN));
		}
		
		public function init():void
		{
			Logger.info("Content.init - buttons.length: " + buttons.length );	
			//addEventListener(MouseEvent.CLICK, onContentMouseClick);
			
			infoButtonsCurrentY = infoButtonsStartY;
			
			/* layout active Buttons */
			for (var i:Number = 0 ; i < buttons.length ; i++)
			{
				
				InfoButton(buttons[i]).x = infoX;
				if (InfoButton(buttons[i]).isActive)
				{
					InfoButton(buttons[i]).y = infoButtonsCurrentY;
					infoButtonsCurrentY += InfoButton(buttons[i]).height + YSpacer;
				}
			}
			/* add the coming soon stuff */
			coming_soon.x = infoX;
			coming_soon.y = infoButtonsCurrentY + YSpacer;
			infoButtonsCurrentY += coming_soon.height + YSpacer * 2;
			
			/* layout inactive Buttons */
			for (i = 0 ; i < buttons.length ; i++)
			{
		
				InfoButton(buttons[i]).x = infoX;
				if (!InfoButton(buttons[i]).isActive)
				{
					InfoButton(buttons[i]).y = infoButtonsCurrentY;
					infoButtonsCurrentY += InfoButton(buttons[i]).height + YSpacer;
				}
			}
			
			
			
			
			addChild(globe);
			addChild(sonisphereTitle);
			addChild(coming_soon);
			addChild(info_bul);
			addChild(info_czec);
			addChild(info_fin);
			addChild(info_gre);
			addChild(info_pol);
			addChild(info_rom);
			addChild(info_sp);
			addChild(info_swe);
			addChild(info_swz);
			addChild(info_swz);
			addChild(info_tur);
			addChild(info_uk);
			
			
			
		}
		
		private function onContentMouseClick(e:MouseEvent):void 
		{
			Logger.info("Content.onContentMouseClick");
			
			dispatchEvent(new BlackHoleEvent(BlackHoleEvent.COLLAPSE));
			
		}
		
	}
	
}